<?

	// reset dbg file
	function dbgStart($FilePrefix=""){
		// dbg file position
		$GLOBALS['dbgFile']="d:/ldwcash/{$FilePrefix}webappsdbg.txt";

		$s = $_SESSION['User'].' -- '.date('Y m d H:i:s')."\n";
		$fPath = $GLOBALS['dbgFile'];
		$hf=fopen($fPath,'w');
		fwrite($hf,$s);	
		fclose($hf);

	}

	// print text in dbg file
	function dbgText($s){
		if (empty($GLOBALS['dbgFile'])) {return;}
		$fPath = $GLOBALS['dbgFile'];
		$hf=fopen($fPath,'a');
		fwrite($hf,$s);	
		fclose($hf);
	}
	
	// print text with new line in dbg file
	function dbgLine($s){
		dbgText($s."\n");
	}
	
	// print var value in dbg file
	function dbgVar($v, $varname=''){
		dbgLine($varname.' = '.print_r($v,TRUE));
	}

	// print GLOBALS and Included files in dbg file
	function dbgDump($exit=TRUE){
		dbgLine('----------------- GLOBALS');
		dbgLine(print_r($GLOBALS,TRUE));
		dbgLine('----------------- Included');
		dbgLine(print_r(get_included_files(),TRUE));
		if ($exit) {
		    exit();
		}
	}

	// Disp the dbg file to screen
	function dbgDisp(){
		echo "<pre>\n";
		include $GLOBALS['dbgFile'];		
	}

	// show var value on the screen
	function dbgDispVar($v, $varname=''){
		echo "<pre>\n";
		echo($varname.' = '.print_r($v,TRUE));
	}

	// start new debugsession
	dbgStart("test_");

	
?>